
<template>
    <div class="app-container assembly-list-page">
        <FilterForm
            ref="FilterForm"
            :data="filterData"
            label-width="85px"
            @search="searchTable"
        />

        <el-row :gutter="10" class="opr-btn-group mb8">
            <el-col :span="1.5">
                <el-button
                    type="primary"
                    plain
                    icon="el-icon-plus"
                    size="mini"
                    @click="handleAdd"
                     v-hasPermi="['storage:woodAssemble:add']"
                    >新增</el-button
                >
            </el-col>
            <el-col :span="1.5">
                <el-button
                    type="danger"
                    plain
                    icon="el-icon-delete"
                    size="mini"
                    :disabled="multiple"
                    @click="handleDelete"
                    v-hasPermi="['storage:woodAssemble:remove']"
                    >删除</el-button
                >
            </el-col>
            <el-col :span="1.5">
                <el-button
                    type="success"
                    plain
                    size="mini"
                    @click="handleAudit(1)"
                    v-hasPermi="['storage:woodAssemble:editAssembleAuditState']"
                    >审核</el-button
                >
            </el-col>
            <el-col :span="1.5">
                <el-button
                    type="success"
                    plain
                    size="mini"
                    @click="handleAudit(0)"
                    v-hasPermi="['storage:woodAssemble:editAssembleAuditState']"
                    >反审核</el-button
                >
            </el-col>
        </el-row>

        <Table
            :api="$Api.storage.assemble.list"
            :params="queryParams"
            height="65vh"
            ref="TableList"
            :selection="true"
            @select="selectionChange"
            @dbClick="dbclick"
            >/depot/receipt/transfer
            <el-table-column label="单据日期" prop="receiptsTime" width="120" />
            <el-table-column label="单据编号" prop="assembleId" width="160" />
            <el-table-column label="制单人" prop="createBy" width="120" />
            <el-table-column label="审核人" prop="auditor" width="120" />
            <el-table-column label="备注" prop="remark" />
            <el-table-column
                label="审核状态"
                align="center"
                key="auditStatus"
                fixed="right"
                width="120"
            >
                <template slot-scope="scope">
                    <span class="success" v-if="scope.row.auditStatus == 1"
                        >已审核</span
                    >
                    <span class="error" v-else>未审核</span>
                </template>
            </el-table-column>
        </Table>
    </div>
</template>

<script>
export default {
    data: () => {
        return {
            ids: [],
            multiple: false,
            table: {
                data: [],
                loading: false,
            },
            queryParams: {
                status: 1,
            },
            showSearch: true,
            exportLoading: false,
            filterData: [
                {
                    label: "单据日期",
                    type: "period_date",
                    st: "beginRegisterTime",
                    end: "endRegisterTime",
                    scale: 2,
                },
                { label: "单据编号", name: "deliveryId" },
                {
                    label: "审核状态",
                    name: "auditStatus",
                    type: "select",
                    select: {
                        option: [
                            {
                                value: "1",
                                label: "已审核",
                            },
                            {
                                value: "0",
                                label: "未审核",
                            },
                        ],
                        selectLabel: "label",
                        selectValue: "value",
                    },
                },
            ],
        };
    },
    methods: {
        dbclick(row) {
            const {assembleId} = row;
            let path = `/assembly/detail/${assembleId}`;
            this.$router.push({
                path,
            });
        },
        getList(params) {
            this.$refs.TableList.getData(params);
        },
        selectionChange(selection) {
            this.ids = selection.map((item) => item.assembleId);
            this.single = selection.length !== 1;
            this.multiple = !selection.length;
        },
        searchTable(params) {
            this.$refs.TableList.getData(params);
        },
        handleAdd() {
            this.$router.push({
                path: "/depot/receipt/assembly",
            });
        },
        handleDelete() {
            let { ids } = this;
            this.$confirm(
                '是否确认删除采购订单信息编号为"' + ids.join() + '"的数据项?',
                "警告",
                {
                    confirmButtonText: "确定",
                    cancelButtonText: "取消",
                    type: "warning",
                }
            ).then(() => {
                this.$Api.storage.assemble.del(ids.join()).then((res) => {
                    this.msgSuccess(res.msg);
                    this.getList();
                });
            });
        },
        handleAudit(audit) {
            let { ids, loading } = this;
            let { FilterForm, TableList } = this.$refs;

            if (TableList.table.loading) return;

            if (!ids.length) {
                this.$message.error("请至少选择一条数据");
                return false;
            }

            this.$Api.storage.assemble
                .audit({
                    assembleIdArray: ids,
                    auditStatus: audit,
                })
                .then((res) => {
                    this.$message.success("操作成功");
                    FilterForm.search();
                })
                .catch(() => {
                    FilterForm.search();
                });
        },
    },
};
</script>

<style lang="scss" scoped>
.assembly-list-page {
    .success {
        color: #67c23a;
    }
    .error {
        color: #f56c6c;
    }
}
</style>